var totalPage;
var object = {};
$(function() {
	var information = {};
	var page = 1;
	var deleteid;
	requestClassification();//渠道
	requestSourceSel();//分级 
	requestRefer(); //已提交数据

	//查询
	$("#firstSearch").click(function() {
			firstSearch();
		})
		//第二排查询
	$("#requestTime").click(function() {
			requestTime();
		})
		//分页，首页
	$("#headPage").click(function() {
			page = 1;
			$("#totalPage").html(page + "/" + totalPage);
			requestPage(page);
		})
		//分页，尾页
	$("#endPage").click(function() {
			$("#totalPage").html(totalPage + "/" + totalPage);
			page = totalPage;
			requestPage(page);
		})
		//分页，上一页
	$("#prevPage").click(function() {
			if (page <= 1) {
				page = 1;
			} else {
				page = page - 1;
				$("#totalPage").html(page + "/" + totalPage);
				requestPage(page);
			}

		})
		//分页，下一页
	$("#nextPage").click(function() {

		if (page >= totalPage) {
			page = page - 1;
		} else {
			page = page + 1;
			$("#totalPage").html(page + "/" + totalPage);
			requestPage(page);
		}

	})


	function requestClassification() {
		var url = "getAllInformationClassification.do"; //分级地址
		var data = {};
		var object = {};
		data = YuXi.util.get(url, "null", function(data) {
			object = data.object;
			//用data循环添加分口信息
			for (var i = 0; i < object.length; i++) {
				var html = "<option  value=" + object[i].id + " >" + object[i].name + "</option>";
				$(".reSearchpes").append(html);
			}
		}, function() {

		}); //请求数据
	}

	function requestSourceSel() {
		var url = "getAllInfomationSource.do"; //渠道地址
		var data = {};
		var object = {};
		data = YuXi.util.get(url, "null", function(data) {
			object = data.object;
			for (var i = 0; i < object.length; i++) {
				var html = "<option value=" + object[i].id + ">" + object[i].name + "</option>";
				$(".reSearchSource ").append(html);
			}

		}, function() {

		});
	}

	function btn() {
		//跳转到详情界面
		$("#tablebody").parent().on("click", ".detail", function() {
			var id = $(this).attr("data-id");
			window.location.href = 'subDetailInfo.jsp?detailId=' + id;
			/* location.search = "?detailId="+id;*/
		})
	}
	//分页
	function requestPage(page) {
		$("#tablebody").html("");

		information.currentPage = page;
		alert("json" + JSON.stringify(information));
		var url = "taskAlreadyFinshList.do";
		YuXi.util.get(url, information, function(data) {
			object = data.list;
			for (var i = 0; i < object.length; i++) {
				var time = YuXi.getTime.get(object[i].createTime);
				if (object[i].informationProfile.length > 15)
					object[i].informationProfile = object[i].informationProfile.substring(0, 15) + "...";

				var html = "<tr ><td>" + (i + 1) + "</td><td >" + object[i].informationProfile + "</td>" +
					"<td >" + time + "</td>" +
					"<td><a data-id=" + object[i].id + " href='javascript:void(0)'; class='detail'>详情</a></td></tr>";


				$("#tablebody").append(html);
			}
		}, function() {
		})
	}
	/*时间段查询*/
	function requestTime() {

		//起始时间
		var start = $("#valStart").val();
		var end = $("#valEnd").val();
		var array = [];
		array = YuXi.timestamp.get(start, end, null);
		information.starttimestamp = array[0];
		information.endtimestamp = array[1];
		//alert(JSON.stringify(information));


		var url = "taskAlreadyFinshList.do";
		YuXi.util.get(url, information, function(data) {
			totalPage = data.totalPage;
			$("#totalPage").html("1/" + totalPage);
			page = 1;
			object = data.list;
			for (var i = 0; i < object.length; i++) {

				var time = YuXi.getTime.get(object[i].createTime);
				if (object[i].informationProfile.length > 15)
					object[i].informationProfile = object[i].informationProfile.substring(0, 15) + "...";

				var html = "<tr ><td>" + (i + 1) + "</td><td >" + object[i].informationProfile + "</td>" +
					"<td >" + time + "</td>" +
					"<td><a data-id=" + object[i].id + " href='javascript:void(0)'; class='detail'>详情</a></td></tr>";


				$("#tablebody").append(html);
			}
		}, function() {
		})

	}
	//向后台请求已提交的信息数据
	function requestRefer() {
		/*
	var data={"list":[{"id":16,"informationAccount":"41469675173784","informationType":0,"informationSourceID":",1,","inputPersonID":"4","informationProfile":"嘻嘻嘻喜喜","informationConternt":"嘻嘻你 信息内容","informationClassificationId":1,"informationSortId":"1","appendix":"http://dfdf","createTime":1469675173784,"userId":4,"jbpmPdId":"prisonArea-24","flowId":"11","flowName":"信息管理"},{"id":17,"informationAccount":"41469675173784","informationType":0,"informationSourceID":",1,","inputPersonID":"4","informationProfile":"嘻嘻嘻喜喜","informationConternt":"嘻嘻你 信息内容","informationClassificationId":1,"informationSortId":"1","appendix":"http://dfdf","createTime":1469675173784,"userId":4,"jbpmPdId":"prisonArea-24","flowId":"11","flowName":"信息管理"},{"id":16,"informationAccount":"41469675173784","informationType":0,"informationSourceID":",1,","inputPersonID":"4","informationProfile":"嘻嘻嘻喜喜","informationConternt":"嘻嘻你 信息内容","informationClassificationId":1,"informationSortId":"1","appendix":"http://dfdf","createTime":1469675173784,"userId":4,"jbpmPdId":"prisonArea-24","flowId":"11","flowName":"信息管理"},{"id":16,"informationAccount":"41469675173784","informationType":0,"informationSourceID":",1,","inputPersonID":"4","informationProfile":"嘻嘻嘻喜喜","informationConternt":"嘻嘻你 信息内容","informationClassificationId":1,"informationSortId":"1","appendix":"http://dfdf","createTime":1469675173784,"userId":4,"jbpmPdId":"prisonArea-24","flowId":"11","flowName":"信息管理"}],"totalRow":1,"totalPage":5,"currentPage":1,"pageSize":10,"isFirstPage":false,"isLastPage":false,"hasPreviusPage":false,"hasNextPage":false}
*/
		var url = "taskAlreadyFinshList.do"; //已提交
		YuXi.util.get(url, "null", function(data) {
			totalPage = data.totalPage;
			$("#totalPage").html("1/" + totalPage);
			object = data.list;
			for (var i = 0; i < object.length; i++) {

				var time = YuXi.getTime.get(object[i].createTime);
				if (object[i].informationProfile.length > 15)
					object[i].informationProfile = object[i].informationProfile.substring(0, 15) + "...";
				var html = "<tr ><td>" + (i + 1) + "</td><td >" + object[i].informationProfile + "</td>" +
					"<td >" + time + "</td>" +
					"<td><a data-id=" + object[i].id + " href='javascript:void(0)'; class='detail'>详情</a></td></tr>";
				$("#tablebody").append(html);
			}

		}, function() {});
		btn();
	}

	//简介，分级，渠道，状态，时间（今天,一周...）查找
	function firstSearch() {

		information.key = $("#profile").val(); //简介
		var curFlowText = $(".state option:selected").val();
		curFlowText == null ? "" : information.curFLow = curFlowText; //当前状态
		information.informationSource = $(".reSearchSource option:selected").val() //来源渠道
		information.informationLv = $(".reSearchpes option:selected").val() //分级
		var value = $(".valTime option:selected").val();
		var array = [];
		array = YuXi.timestamp.get(null, null, value);
		information.startTimestamp = array[0];
		information.endTimestamp = array[1];
		alert(JSON.stringify(information));
		//查询数据传送给后台
		var url = "taskAlreadyFinshList.do"; //地址----------------------------------
		YuXi.util.get(url, information, function(data) {
			totalPage = data.totalPage;
			$("#totalPage").html("1/" + totalPage);
			page = 1;

			var object = data.list;
			$("#tablebody").html("");

			for (var i = 0; i < object.length; i++) {
				var time = YuXi.getTime.get(object[i].createTime);
				if (object[i].informationProfile.length > 15)
					object[i].informationProfile = object[i].informationProfile.substring(0, 15) + "...";
				var html = "<tr ><td>" + (i + 1) + "</td><td >" + object[i].informationProfile + "</td>" +
					"<td >" + time + "</td>" +
					"<td><a data-id=" + object[i].id + " href='javascript:void(0)'; class='detail'>详情</a></td></tr>";
				$("#tablebody").append(html);
			}

		}, function() {
		});
		btn();
	}
})